package vn.com.aptech.msh.business;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.Root;
import vn.com.aptech.msh.entities.Faq;
import vn.com.aptech.msh.entities.FaqGroup;

/**
 *
 * @author trietto
 */
@Stateless
public class FAQBean implements IFAQBean {

    @PersistenceContext(unitName = "MySweetHome-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public FAQBean() {
    }

    @Override
    public List<FaqGroup> allFaqsGroup() {
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaQuery<FaqGroup> cq = cb.createQuery(FaqGroup.class);
        Root<FaqGroup> group = cq.from(FaqGroup.class);
        //Join<FaqGroup, Faq> join = group.join("faqList");
        cq.select(group);        
        TypedQuery<FaqGroup> query = em.createQuery(cq);
        return query.getResultList();
    }
}
